angular.module('myApp.services',[])
    .factory('HitService',function($q,$http){
        var service={
            count:function(){
                //申请promise resolve成功执行   reject错误执行
                var d=$q.defer();
                $http.get('/hits')
                    .success(function(data,status){
                        d.resolve(data);
                    }).error(function(data,status){
                        d.reject(data);
                    });
                return d.promise;
            },
            registerHit:function(){
                var d=$q.defer();
                $http.post('/hit',{})
                    .success(function(data,status){
                        d.resolve(data.hits);
                    }).error(function(data,status){
                        d.reject(data.hits);
                    });
                return d.promise;
            },
            //用户登录
            login:function(name,password){
                var user=angular.toJson({'name':name,'password':password});
                var d=$q.defer();
                $http.post('/login',user)
                    .success(function(data,status){
                        d.resolve(data);
                    }).error(function(data,status){
                        d.reject(data.hits);
                    });
                return d.promise;
            },
            queryLuckList:function(pro,keyword){
                keyword= $.trim(keyword);
                var num=angular.toJson({'num':pro ,'keyword':keyword});
                var d=$q.defer();
                $http.post('/userList',num)
                    .success(function(data){
                        d.resolve(data);
                    }).error(function(data){
                        d.reject(data);
                    });
                return d.promise;
            },
            addUser:function(user){
                var users=angular.toJson({'name':user.name,'password':user.password,'number':user.number,'sex':user.sex,'address':user.address});
                var d=$q.defer();
                $http.post('/addUser',users)
                    .success(function(data){
                        d.resolve(data);
                    }).error(function(data){
                        d.reject(data);
                    });
                return d.promise;
            },
            deleteUser:function(id){
                var users=angular.toJson({'id':id});
                var d=$q.defer();
                $http.post('/deleteUser',users)
                    .success(function(data){
                        d.resolve(data);
                    }).error(function(data){
                        d.reject(data);
                    });
                return d.promise;
            }
        };
        return service;
    })
    .factory('bigData',function($q,$http){
        var service={

        };
        return service;
    });
